import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // 登录
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login')
  },
  // 订阅
  {
    path: '/subscribe',
    name: 'Subscribe',
    component: () => import('../views/subscribe/Index.vue')
  },
  {
    path: '/subscribe/addSubscribe',
    name: 'AddSubscribe',
    component: () => import('../views/subscribe/AddSubscribe.vue')
  },
  {
    path: '/subscribe/resource',
    name: 'Resource',
    component: () => import('../views/subscribe/ResourceList.vue')
  },
  {
    path: '/subscribe/bookDetail',
    name: 'BookDetail',
    component: () => import('../views/subscribe/BookDetail.vue')
  },
  {
    path: '/',
    name: 'Home',
    redirect: '/recommend'
  },
  // 推荐
  {
    path: '/recommend',
    name: 'Recommend',
    component: () => import('../views/recommend/Index.vue')
  },
  {
    path: '/recommend/book',
    name: 'Book',
    component: () => import('../views/recommend/Book.vue')
  },
  {
    path: '*',
    component: () => import('@/views/404'),
    name: '404'
  }
]

const router = new VueRouter({
  routes
})

// const whiteList = ['/login']

// // 导航守卫
// router.beforeEach((to, from, next) => {
//   const token = window.localStorage.getItem('REC-TOKEN')
//   if (whiteList.indexOf(to.path) !== -1) {
//     if (token && token.length) {
//       next('/')
//     } else {
//       next()
//     }
//   } else {
//     if (token && token.length) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })

export default router
